#include "PatientModel.h"


namespace UserManagementSystem {



PatientModel::PatientModel(UserRepository *repository, QObject *parent)
    :QAbstractListModel(parent),m_userDataRepository(repository)
{
    qDebug()<<__FUNCTION__;
    m_patients=repository->GetPatientData();
}

QVariant PatientModel::data(const QModelIndex &index, int role) const
{
    if(!index.isValid()||role!=Qt::DisplayRole){
        return {};
    }

    return QVariant::fromValue(m_patients.at(index.row()));

}

int PatientModel::rowCount(const QModelIndex &parent) const
{
    //返回患者数量
    return m_patients.size();
}

bool PatientModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if(!index.isValid()||role!=Qt::EditRole){
        return false;
    }

    //取到index所指向行数的患者数据信息
    PatientData patient=m_patients[index.row()];
    return true;
}

void PatientModel::LoadPatients()
{
    m_patients=m_userDataRepository->GetPatientData();
}

}
